<template>
    <div>
        <h1>修改</h1>
        <table class="table">
            <tbody>
                 <tr>
                    <td>图片</td>
                    <td>
                        <input type="file" @change="Upload">
                        <img :src="axios.defaults.baseURL+datapost.img" style="width: 50px; height: 50px;">
                    
                    </td>
                </tr>
                <tr>
                    <td>姓名</td>
                    <td><input type="text" v-model="datapost.userName"></td>
                </tr>
                <tr>
                    <td>类型</td>
                    <select v-model="datapost.userTypeId">
                        <option value="0">请选择</option>
                        <option v-for="d in dataa" :value="d.userTypeId">{{ d.userTypeName }}</option>
                    </select>
                </tr>

                <tr>
                    <td>性别</td>
                    <td >
                        <input type="radio" name="1" value="1" v-model="datapost.userSex">男
                        <input type="radio" name="1" value="2" v-model="datapost.userSex">女
                    </td>
                </tr>
                 <tr>
                    <td>身份证</td>
                    <td >
                       <input type="text" v-model="datapost.userPonple">
                    </td>
                </tr>
                 <tr>
                    <td>手机号</td>
                    <td >
                       <input type="text" v-model="datapost.userPhone">
                    </td>
                </tr>
                <tr>
                    <td>地址</td>
                    <td >
                       <input type="text" v-model="datapost.userAddr">
                    </td>
                </tr>
                <tr>
                    <td>名族</td>
                    <td >
                       <input type="text" v-model="datapost.userMZ">
                    </td>
                </tr>
                  <tr>
                    <td>小区</td>
                    <td >
                       <input type="text" v-model="datapost.userXQ">
                    </td>
                </tr>
                  <tr>
                    <td>房间号</td>
                    <td >
                       <input type="text" v-model="datapost.userRoom">
                    </td>
                </tr>
                 <tr>
                    <td>状态</td>
                    <td >
                       <input type="radio" name="2" value="1" v-model="datapost.userStart">已审核
                        <input type="radio" name="2" value="2" v-model="datapost.userStart">未审核
                    </td>
                </tr>
                <tr>
                    <td><input type="button" value="修改" @click="Update"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>
<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted} from 'vue';
import {useRoute,useRouter} from 'vue-router';
const route = useRoute()
const router = useRouter()
onMounted(()=>{
    Bang()
    FT()
})


const FT=()=>{
    let mid = route.query.id
    axios.get("/api/User/FT",{params:{id:mid}}).then(res=>{
        datapost.value = res.data;
    })
}

const dataa  = ref([])
const Bang=()=>{
    axios.get("/api/UserType/ShowType").then(res=>{
        dataa.value=res.data;
    })
}
const Upload=(ev:any)=>{
    let f = ev.target.files[0];
    let fd = new FormData();
    fd.append("file",f)

    axios.post("/api/Upload/Upload",fd).then(res=>{
        datapost.value.img = res.data;
    })
}

const datapost = ref({
  "id": 0,
  "img": "string",
  "userName": "string",
  "userTypeId": 0,
  "userSex": 0,
  "userPonple": "string",
  "userPhone": "string",
  "userAddr": "string",
  "userMZ": "string",
  "userXQ": "string",
  "userRoom": "string",
  "userStart": 0 
})

const Update=()=>{
    axios.put("/api/User/Update",datapost.value).then(res=>{
        if(res.data>0)
        {
            alert("修改成功")
            router.push("/Show");
        }
        else{
            alert("修改失败")
        }
    })
}
</script>
<style scoped>
</style>